/**
 * Created by yuesir on 2017/6/29.
 */

$.ajaxSetup({
    headers: {
        'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
    }
});

//文章后台审核
$('.post-audit').click(function (e) {
    var $target = $(e.target);

    var status = $target.attr('post-action-status');
    var postId = $target.attr('post-id');

    var targetUrl = '/admin/posts/' + postId + '/status';
    $.ajax({
        "url" : targetUrl,
        "type":'POST',
        "data": {"status" : status},
        'dataType' : 'JSON',
        "success":function (data) {
            if (data.error > 0) {
                alert(data.msg);
                return;
            }

            $target.closest('tr').remove();
        }
    })
});


//删除对应的专题
$('.resource-delete').click(function (e) {
    if ( false === confirm('你确定要删除对应的专题页吗?')) return;

    var $target = $(e.target);
    var targetUrl = $target.attr('delete-url');

    $.ajax({
        "url" : targetUrl,
        "type":'POST',
        "data": {"_method" : 'DELETE'},
        'dataType' : 'JSON',
        "success":function (data) {
            if (data.error > 0) {
                alert(data.msg);
                return;
            }

            $target.closest('tr').remove();
        }
    });

    return false;   //阻止默认的行为
});